/**
* @desc desc
* @author 钱炜亮
* @date 2024-04-21
*/
<template>
  <common-page>
    <view class="page-box-company">
			<u--form
				labelPosition="left"
				labelWidth="160rpx"
				:model="formData"
				:rules="rules"
				ref="uForm"
			>
				<u-form-item
					label="企业名称"
					prop="companyName"
					required
					borderBottom
				>
					<u--input
						v-model="formData.companyName"
						border="none"
						placeholder="请填写企业名称"
						placeholderClass="inputPlaceholder"
					></u--input>
				</u-form-item>
				<u-form-item
					label="联系人"
					prop="contacts"
					borderBottom
					required
				>
					<u--input
						v-model="formData.contacts"
						border="none"
						placeholder="请填写联系人"
						placeholderClass="inputPlaceholder"
					></u--input>
				</u-form-item>
				<u-form-item
					label="联系电话"
					prop="contactsPhone"
					borderBottom
					required
				>
					<u--input
						v-model="formData.contactsPhone"
						border="none"
						placeholder="请填写联系电话"
						placeholderClass="inputPlaceholder"
					></u--input>
				</u-form-item>
				<u-form-item
					label="企业邮箱"
					prop="email"
					borderBottom
				>
					<u--input
						v-model="formData.email"
						border="none"
						placeholder="请填写企业邮箱"
						placeholderClass="inputPlaceholder"
					></u--input>
				</u-form-item>
				<u-form-item
					label="企业地址"
					prop="address"
					borderBottom
				>
					<u--input
						v-model="formData.address"
						border="none"
						placeholder="请填写企业地址"
						placeholderClass="inputPlaceholder"
					></u--input>
				</u-form-item>
			</u--form>
    </view>
		<u-button text="保存" type="primary" color="#417CE9" @click="bindSubmit"></u-button>
  </common-page>
</template>

<script>
export default {
	data() {
		return {
			formData: {
				companyName: '',
				contacts: '',
				contactsPhone: '',
				email: '',
				address: '',
				id: '',
				userId: ''
			},
			rules: {
				'companyName': {
					type: 'string',
					required: true,
					message: '请填写企业名称',
					trigger: ['blur', 'change']
				},
				'contacts': {
					type: 'string',
					required: true,
					message: '请填写联系人',
					trigger: ['blur', 'change']
				},
				'contactsPhone': [{
					type: 'string',
					required: true,
					message: '请填写联系电话',
					trigger: ['blur', 'change']
				}, {
					pattern: /^1[3-9]\d{9}$/,
					message: '请填写正确手机号格式',
					trigger: ['blur']
				}]
			}
		};
	},
	onLoad() {
		this.getCompanyInfoData();
	},
	methods: {
		// 获取公司详情
		async getCompanyInfoData() {
			const [err, result] = await this.$to(uni.$u.http.get('/jeecg-boot/api/v1-public/mini-program-company/companyInfo'));
			if (err) return;
			this.formData = result;
		},
		bindSubmit() {
			this.$refs.uForm.validate().then(async(res) => {
				const [err, result] = await this.$to(uni.$u.http.post('/jeecg-boot/api/v1-public/mini-program-company/updateCompanyInfo', this.formData));
				if (err) return;
				uni.$u.toast('修改成功');
				uni.$emit('bindUpdateInfo');
				setTimeout(() => {
					uni.navigateBack();
				}, 1500);
			}).catch(errors => {
				uni.$u.toast('校验失败');
			});
		}
		/* ====== S 事件区域 ====== */

		/* ====== E 事件区域 ====== */
		/* ====== S 通用逻辑 ====== */

		/* ====== E 通用逻辑 ====== */
		/* ====== S 接口定义 ====== */

		/* ====== E 接口定义 ====== */
	}
};
</script>

<style>

</style>
<style lang="scss" scoped>
.page-box-company {
	background-color: #fff;
	border-radius: 20rpx;
	margin-top: 32rpx;
	padding: 20rpx 40rpx;

}

::v-deep .u-button {
	margin-top: 60rpx;
	border-radius: 80rpx !important;
	.u-button__text {
		font-size: 32rpx !important;
		font-weight: bold;
	}
}
</style>
